/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.dialogs;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import br.ufmg.dees.insane.commons.dialogs.DecimalField;
import br.ufmg.dees.insane.commons.dialogs.TabbedDialog;
import br.ufmg.dees.insane.model.disc.node.Node;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;

/**
 * A class representing creation dialog on screen.
 * For example:
 * <pre>
 *    NodesAttributesDialog dgl = new NodesAttributesDialog(parent, this);
 *    dgl.pack();
 * </pre>
 *
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @see gui.InsaneInternalInterface
 * @since March 2004
 */
public final class NodesAttributesDialog extends TabbedDialog {
	
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private InsaneInternalInterface parent;
	private NumberFormat numberFormat;
	private boolean springPossible = true;
	
	private String gAnlType;
	
	private DecimalField AngleField;
	public double Angle;
	
	private DecimalField FxField;
	private DecimalField FyField;
	private DecimalField FzField;
	private DecimalField MxField;
	private DecimalField MyField;
	private DecimalField MzField;
	public double Fx;
	public double Fy;
	public double Fz;
	public double Mx;
	public double My;
	public double Mz;
	
	private DecimalField KxField;
	private DecimalField KyField;
	private DecimalField KzField;
	private DecimalField KrxField;
	private DecimalField KryField;
	private DecimalField KrzField;
	public double Kx;
	public double Ky;
	public double Kz;
	public double Krx;
	public double Kry;
	public double Krz;
	
	private DecimalField DxField;
	private DecimalField DyField;
	private DecimalField DzField;
	private DecimalField RxField;
	private DecimalField RyField;
	private DecimalField RzField;
	public double Dx;
	public double Dy;
	public double Dz;
	public double Rx;
	public double Ry;
	public double Rz;
	
	private JCheckBox restraintRdx = new JCheckBox("");
	private JCheckBox restraintRdy = new JCheckBox("");
	private JCheckBox restraintRdz = new JCheckBox("");
	private JCheckBox restraintRrx = new JCheckBox("");
	private JCheckBox restraintRry = new JCheckBox("");
	private JCheckBox restraintRrz = new JCheckBox("");
	public boolean Rdx;
	public boolean Rdy;
	public boolean Rdz;
	public boolean Rrx;
	public boolean Rry;
	public boolean Rrz;
	private JLabel labelRdx = new JLabel("Dx       ");
	private JLabel labelRdy = new JLabel("Dy       ");
	private JLabel labelRdz = new JLabel("Dz       ");
	private JLabel labelRrx = new JLabel("Rx       ");
	private JLabel labelRry = new JLabel("Ry       ");
	private JLabel labelRrz = new JLabel("Rz       ");
	private JLabel figuraRdx;
	private JLabel figuraRdy;
	private JLabel figuraRdz;
	private JLabel figuraRrx;
	private JLabel figuraRry;
	private JLabel figuraRrz;
	
//*****************************************************************************
	
	/**
	 * Constructor method, calling super with the especific title.
	 *
	 * @param parent The parent of the class.
	 * @see gui.InsaneInternalInterface
	 */
	public NodesAttributesDialog(InsaneInternalInterface parent) {
		this.parent = parent;
		gAnlType = parent.getModel().getDiscreteModel().getGlobalAnalysisModel().getType();
		
		setUpFormat();
		setUpFields();
		
		//Sets up the angle panel
		JPanel anglePane = new JPanel();
		anglePane.setPreferredSize(new Dimension(360, 280));
		anglePane.setLayout(new GridLayout(4,1,2,2));
		JPanel blankPane = new JPanel();
		anglePane.add(blankPane);
		JPanel anglePicPane = new JPanel();
		anglePicPane.setLayout(new GridLayout(1,1,2,2));
		anglePane.add(anglePicPane);
		JPanel angleValuePane = new JPanel();
		anglePane.add(angleValuePane);
		JPanel blankPane2 = new JPanel();
		anglePane.add(blankPane2);
		
		anglePicPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/NodeAngle64.gif")) ));
		angleValuePane.add(new JLabel(parent.getResourceBundle().getString("dNAngDialog01")));
		angleValuePane.add(AngleField);
		
		AngleFieldHandler angleHandler = new AngleFieldHandler();
		AngleField.addKeyListener(angleHandler);
		
		// Sets up the force panel
		JPanel forcePane = new JPanel();
		forcePane.setPreferredSize(new Dimension(360, 280));
		forcePane.setLayout(new GridLayout(4,1,2,2));
		JPanel forceFPane = new JPanel();
		forceFPane.setLayout(new GridLayout(1,3,2,2));
		forcePane.add(forceFPane);
		JPanel forceValueFPane = new JPanel();
		forceValueFPane.setLayout(new GridLayout(1,3,2,2));
		forcePane.add(forceValueFPane);
		JPanel forceMPane = new JPanel();
		forceMPane.setLayout(new GridLayout(1,3,2,2));
		forcePane.add(forceMPane);
		JPanel forceValueMPane = new JPanel();
		forceValueMPane.setLayout(new GridLayout(1,3,2,2));
		forcePane.add(forceValueMPane);
		
		forceFPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ForceX64.gif")) ));
		forceFPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ForceY64.gif")) ));
		forceFPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ForceZ64.gif")) ));
		forceMPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/MomentX64.gif")) ));
		forceMPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/MomentY64.gif")) ));
		forceMPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/MomentZ64.gif")) ));
		
		JPanel forceFxPane = new JPanel();
		JPanel forceFyPane = new JPanel();
		JPanel forceFzPane = new JPanel();
		JPanel forceMxPane = new JPanel();
		JPanel forceMyPane = new JPanel();
		JPanel forceMzPane = new JPanel();
		
		forceFxPane.add(new JLabel("Fx:"));
		forceFyPane.add(new JLabel("Fy:"));
		forceFzPane.add(new JLabel("Fz:"));
		forceMxPane.add(new JLabel("Mx:"));
		forceMyPane.add(new JLabel("My:"));
		forceMzPane.add(new JLabel("Mz:"));
		
		forceFxPane.add(FxField);
		forceFyPane.add(FyField);
		forceFzPane.add(FzField);
		forceMxPane.add(MxField);
		forceMyPane.add(MyField);
		forceMzPane.add(MzField);
		
		if (gAnlType.equals("PlaneFrame")) {
			FzField.setEnabled(false);
			MxField.setEnabled(false);
			MyField.setEnabled(false);
		}
		else if (gAnlType.equals("PlaneTruss")) {
			FzField.setEnabled(false);
			MxField.setEnabled(false);
			MyField.setEnabled(false);
			MzField.setEnabled(false);
		}
		else if (gAnlType.equals("Beam")) {
			FxField.setEnabled(false);
			FzField.setEnabled(false);
			MxField.setEnabled(false);
			MyField.setEnabled(false);
		}
		else if (gAnlType.equals("Grid")) {
			FxField.setEnabled(false);
			FzField.setEnabled(false);
			MyField.setEnabled(false);
		}
		
		forceValueFPane.add(forceFxPane);
		forceValueFPane.add(forceFyPane);
		forceValueFPane.add(forceFzPane);
		forceValueMPane.add(forceMxPane);
		forceValueMPane.add(forceMyPane);
		forceValueMPane.add(forceMzPane);
		
		// Sets up the spring panel
		JPanel springPane = new JPanel();
		springPane.setPreferredSize(new Dimension(360, 280));
		springPane.setLayout(new GridLayout(4,1,2,2));
		JPanel springDPane = new JPanel();
		springDPane.setLayout(new GridLayout(1,3,2,2));
		springPane.add(springDPane);
		JPanel springValueDPane = new JPanel();
		springValueDPane.setLayout(new GridLayout(1,3,2,2));
		springPane.add(springValueDPane);
		JPanel springRPane = new JPanel();
		springRPane.setLayout(new GridLayout(1,3,2,2));
		springPane.add(springRPane);
		JPanel springValueRPane = new JPanel();
		springValueRPane.setLayout(new GridLayout(1,3,2,2));
		springPane.add(springValueRPane);
		
		springDPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SpringKx64.gif")) ));
		springDPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SpringKy64.gif")) ));
		springDPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SpringKz64.gif")) ));
		springRPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SpringKrx64.gif")) ));
		springRPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SpringKry64.gif")) ));
		springRPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SpringKrz64.gif")) ));
		
		JPanel springKxPane = new JPanel();
		JPanel springKyPane = new JPanel();
		JPanel springKzPane = new JPanel();
		JPanel springKrxPane = new JPanel();
		JPanel springKryPane = new JPanel();
		JPanel springKrzPane = new JPanel();
		
		springKxPane.add(new JLabel("Kx:"));
		springKyPane.add(new JLabel("Ky:"));
		springKzPane.add(new JLabel("Kz:"));
		springKrxPane.add(new JLabel("Krx:"));
		springKryPane.add(new JLabel("Kry:"));
		springKrzPane.add(new JLabel("Krz:"));
		
		springKxPane.add(KxField);
		springKyPane.add(KyField);
		springKzPane.add(KzField);
		springKrxPane.add(KrxField);
		springKryPane.add(KryField);
		springKrzPane.add(KrzField);
		
		springValueDPane.add(springKxPane);
		springValueDPane.add(springKyPane);
		springValueDPane.add(springKzPane);
		springValueRPane.add(springKrxPane);
		springValueRPane.add(springKryPane);
		springValueRPane.add(springKrzPane);
		
		KxField.setEnabled(false);
		KyField.setEnabled(false);
		KzField.setEnabled(false);
		KrxField.setEnabled(false);
		KryField.setEnabled(false);
		KrzField.setEnabled(false);
		
		// Sets up the preDisplacement panel
		JPanel displacePane = new JPanel();
		displacePane.setPreferredSize(new Dimension(360, 280));
		displacePane.setLayout(new GridLayout(4,1,2,2));
		JPanel displaceDPane = new JPanel();
		displaceDPane.setLayout(new GridLayout(1,3,2,2));
		displacePane.add(displaceDPane);
		JPanel displaceValueDPane = new JPanel();
		displaceValueDPane.setLayout(new GridLayout(1,3,2,2));
		displacePane.add(displaceValueDPane);
		JPanel displaceRPane = new JPanel();
		displaceRPane.setLayout(new GridLayout(1,3,2,2));
		displacePane.add(displaceRPane);
		JPanel displaceValueRPane = new JPanel();
		displaceValueRPane.setLayout(new GridLayout(1,3,2,2));
		displacePane.add(displaceValueRPane);
		
		displaceDPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDx64.gif")) ));
		displaceDPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDy64.gif")) ));
		displaceDPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDz64.gif")) ));
		displaceRPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRx64.gif")) ));
		displaceRPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRy64.gif")) ));
		displaceRPane.add(new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRz64.gif")) ));
		
		JPanel displaceDxPane = new JPanel();
		JPanel displaceDyPane = new JPanel();
		JPanel displaceDzPane = new JPanel();
		JPanel displaceRxPane = new JPanel();
		JPanel displaceRyPane = new JPanel();
		JPanel displaceRzPane = new JPanel();
		
		displaceDxPane.add(new JLabel("Dx:"));
		displaceDyPane.add(new JLabel("Dy:"));
		displaceDzPane.add(new JLabel("Dz:"));
		displaceRxPane.add(new JLabel("Rx:"));
		displaceRyPane.add(new JLabel("Ry:"));
		displaceRzPane.add(new JLabel("Rz:"));
		
		displaceDxPane.add(DxField);
		displaceDyPane.add(DyField);
		displaceDzPane.add(DzField);
		displaceRxPane.add(RxField);
		displaceRyPane.add(RyField);
		displaceRzPane.add(RzField);
		
		displaceValueDPane.add(displaceDxPane);
		displaceValueDPane.add(displaceDyPane);
		displaceValueDPane.add(displaceDzPane);
		displaceValueRPane.add(displaceRxPane);
		displaceValueRPane.add(displaceRyPane);
		displaceValueRPane.add(displaceRzPane);
		
		if (gAnlType.equals("PlaneFrame")) {
			DzField.setEnabled(false);
			RxField.setEnabled(false);
			RyField.setEnabled(false);
		}
		else if (gAnlType.equals("PlaneTruss")) {
			DzField.setEnabled(false);
			RxField.setEnabled(false);
			RyField.setEnabled(false);
			RzField.setEnabled(false);
		}
		else if (gAnlType.equals("Beam")) {
			DxField.setEnabled(false);
			DzField.setEnabled(false);
			RxField.setEnabled(false);
			RyField.setEnabled(false);
		}
		else if (gAnlType.equals("Grid")) {
			DxField.setEnabled(false);
			DzField.setEnabled(false);
			RyField.setEnabled(false);
		}
		
		// Sets up the restraint panel
		JPanel restraintPane = new JPanel();
		restraintPane.setPreferredSize(new Dimension(360, 280));
		restraintPane.setLayout(new GridLayout(4,1,2,2));
		JPanel restraintDPane = new JPanel();
		restraintDPane.setLayout(new GridLayout(1,3,2,2));
		restraintPane.add(restraintDPane);
		JPanel restraintValueDPane = new JPanel();
		restraintValueDPane.setLayout(new GridLayout(1,3,2,2));
		restraintPane.add(restraintValueDPane);
		JPanel restraintRPane = new JPanel();
		restraintRPane.setLayout(new GridLayout(1,3,2,2));
		restraintPane.add(restraintRPane);
		JPanel restraintValueRPane = new JPanel();
		restraintValueRPane.setLayout(new GridLayout(1,3,2,2));
		restraintPane.add(restraintValueRPane);
		
		figuraRdx = new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDx64.gif")) ); 
		restraintDPane.add(figuraRdx);
		figuraRdy = new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDy64.gif")) );
		restraintDPane.add(figuraRdy);
		figuraRdz = new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDz64.gif")) );
		restraintDPane.add(figuraRdz);
		figuraRrx = new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRx64.gif")) );
		restraintRPane.add(figuraRrx);
		figuraRry = new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRy64.gif")) );
		restraintRPane.add(figuraRry);
		figuraRrz = new JLabel( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRz64.gif")) );
		restraintRPane.add(figuraRrz);
		
		JPanel restraintRdxPane = new JPanel();
		JPanel restraintRdyPane = new JPanel();
		JPanel restraintRdzPane = new JPanel();
		JPanel restraintRrxPane = new JPanel();
		JPanel restraintRryPane = new JPanel();
		JPanel restraintRrzPane = new JPanel();
		
		if ( restraintRdx.isSelected() ) {
			labelRdx.setText("Dx = 0");
			figuraRdx.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintDx64.gif")) );
		}
		if ( restraintRdy.isSelected() ) {
			labelRdy.setText("Dy = 0");
			figuraRdy.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintDy64.gif")) );
		}
		if ( restraintRdz.isSelected() ) {
			labelRdz.setText("Dz = 0");
			figuraRdz.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintDz64.gif")) );
		}
		if ( restraintRrx.isSelected() ) {
			labelRrx.setText("Rx = 0");
			figuraRrx.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintRx64.gif")) );
		}
		if ( restraintRry.isSelected() ) {
			labelRry.setText("Ry = 0");
			figuraRry.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintRy64.gif")) );
		}
		if ( restraintRrz.isSelected() ) {
			labelRrz.setText("Rz = 0");
			figuraRrz.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintRz64.gif")) );
		}
		
		// register events for JCheckBox
		CheckBoxHandlerRdx handlerRdx = new CheckBoxHandlerRdx();
		restraintRdx.addItemListener( handlerRdx );
		CheckBoxHandlerRdy handlerRdy = new CheckBoxHandlerRdy();
		restraintRdy.addItemListener( handlerRdy );
		CheckBoxHandlerRdz handlerRdz = new CheckBoxHandlerRdz();
		restraintRdz.addItemListener( handlerRdz );
		CheckBoxHandlerRrx handlerRrx = new CheckBoxHandlerRrx();
		restraintRrx.addItemListener( handlerRrx );
		CheckBoxHandlerRry handlerRry = new CheckBoxHandlerRry();
		restraintRry.addItemListener( handlerRry );
		CheckBoxHandlerRrz handlerRrz = new CheckBoxHandlerRrz();
		restraintRrz.addItemListener( handlerRrz );
		// end of register
		
		restraintRdxPane.add(restraintRdx);
		restraintRdxPane.add(labelRdx);
		restraintRdyPane.add(restraintRdy);
		restraintRdyPane.add(labelRdy);
		restraintRdzPane.add(restraintRdz);
		restraintRdzPane.add(labelRdz);
		restraintRrxPane.add(restraintRrx);
		restraintRrxPane.add(labelRrx);
		restraintRryPane.add(restraintRry);
		restraintRryPane.add(labelRry);
		restraintRrzPane.add(restraintRrz);
		restraintRrzPane.add(labelRrz);
		
		restraintValueDPane.add(restraintRdxPane);
		restraintValueDPane.add(restraintRdyPane);
		restraintValueDPane.add(restraintRdzPane);
		restraintValueRPane.add(restraintRrxPane);
		restraintValueRPane.add(restraintRryPane);
		restraintValueRPane.add(restraintRrzPane);
		
		if (gAnlType.equals("Beam") || gAnlType.equals("PlaneFrame") || gAnlType.equals("PlaneTruss") ) {
			restraintRdz.setEnabled(false);
			restraintRrx.setEnabled(false);
			restraintRry.setEnabled(false);
		}
		else if (gAnlType.equals("Grid")) {
			restraintRdx.setEnabled(false);
			restraintRdz.setEnabled(false);
			restraintRry.setEnabled(false);
		}
		
		//Enabling spring fields if respective restraint is not selected
		//and global analysis model considers the respective degree of freedom
		if (this.parent.getController().getSelection().size() == 1 ) {
			Node node = (Node)this.parent.getController().getSelection().get(0);
			
			if (gAnlType.equals("PlaneFrame")) {
				if (!node.getRestraint(0))
					KxField.setEnabled(true);
				if (!node.getRestraint(1))
					KyField.setEnabled(true);
				if (!node.getRestraint(5))
					KrzField.setEnabled(true);
			}
			else if (gAnlType.equals("PlaneTruss")) {
				if (!node.getRestraint(0))
					KxField.setEnabled(true);
				if (!node.getRestraint(1))
					KyField.setEnabled(true);
			}
			else if (gAnlType.equals("Beam")) {
				if (!node.getRestraint(1))
					KyField.setEnabled(true);
				if (!node.getRestraint(5))
					KrzField.setEnabled(true);
			}
			else if (gAnlType.equals("Grid")) {
				if (!node.getRestraint(1))
					KyField.setEnabled(true);
				if (!node.getRestraint(3))
					KrxField.setEnabled(true);
				if (!node.getRestraint(5))
					KrzField.setEnabled(true);
			}
			
		}
		
//		Adding tabs to dialog
		addTab(parent.getResourceBundle().getString("mAngle"), anglePane);
		addTab(parent.getResourceBundle().getString("mRestraints"), restraintPane);
		addTab(parent.getResourceBundle().getString("mForces"), forcePane);
		addTab(parent.getResourceBundle().getString("mPreDisplacements"), displacePane);
		addTab(parent.getResourceBundle().getString("mSpring"), springPane);
		
    }
	
//*****************************************************************************
	
    public int showDialog() {
    	return super.showDialog(parent, parent.getResourceBundle().getString("mNodalAttributes"));
    }
	
//*****************************************************************************
	
	/**
	 * This method is executed on OK button click.
	 */
	public void approvedPerform() {
		try {
			Angle = AngleField.getValue();
			
			Fx = FxField.getValue();
			Fy = FyField.getValue();
			Fz = FzField.getValue();
			Mx = MxField.getValue();
			My = MyField.getValue();
			Mz = MzField.getValue();
			
			Kx = KxField.getValue();
			Ky = KyField.getValue();
			Kz = KzField.getValue();
			Krx = KrxField.getValue();
			Kry = KryField.getValue();
			Krz = KrzField.getValue();
			
			Dx = DxField.getValue();
			Dy = DyField.getValue();
			Dz = DzField.getValue();
			Rx = RxField.getValue();
			Ry = RyField.getValue();
			Rz = RzField.getValue();
			
			Rdx = restraintRdx.isSelected();
			Rdy = restraintRdy.isSelected();
			Rdz = restraintRdz.isSelected();
			Rrx = restraintRrx.isSelected();
			Rry = restraintRry.isSelected();
			Rrz = restraintRrz.isSelected();
		} catch (Exception e) {
			Toolkit.getDefaultToolkit().beep();
			this.setVisible(false);
		}
	}
	
//*****************************************************************************
	
	/**
	 * Sets up the number formater
	 */
	private void setUpFormat() {
		numberFormat = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
		numberFormat.setMinimumFractionDigits(parent.getModelState().getPrecision());
		numberFormat.setMaximumFractionDigits(8);
	}
	
//*****************************************************************************
	
	/**
	 * Sets up fields
	 */
	private void setUpFields() {
		if (this.parent.getController().getSelection().size() == 1 ) {
			Node node = (Node)this.parent.getController().getSelection().get(0);
			
			AngleField = new DecimalField(node.getAngle(), 7, numberFormat);
			
			FxField = new DecimalField(node.getForce(0), 7, numberFormat);
			FyField = new DecimalField(node.getForce(1), 7, numberFormat);
			FzField = new DecimalField(node.getForce(2), 7, numberFormat);
			MxField = new DecimalField(node.getForce(3), 7, numberFormat);
			MyField = new DecimalField(node.getForce(4), 7, numberFormat);
			MzField = new DecimalField(node.getForce(5), 7, numberFormat);
			
			KxField = new DecimalField(node.getSpring(0), 7, numberFormat);
			KyField = new DecimalField(node.getSpring(1), 7, numberFormat);
			KzField = new DecimalField(node.getSpring(2), 7, numberFormat);
			KrxField = new DecimalField(node.getSpring(3), 7, numberFormat);
			KryField = new DecimalField(node.getSpring(4), 7, numberFormat);
			KrzField = new DecimalField(node.getSpring(5), 7, numberFormat);
			
			DxField = new DecimalField(node.getPreDisplacement(0), 7, numberFormat);
			DyField = new DecimalField(node.getPreDisplacement(1), 7, numberFormat);
			DzField = new DecimalField(node.getPreDisplacement(2), 7, numberFormat);
			RxField = new DecimalField(node.getPreDisplacement(3), 7, numberFormat);
			RyField = new DecimalField(node.getPreDisplacement(4), 7, numberFormat);
			RzField = new DecimalField(node.getPreDisplacement(5), 7, numberFormat);
			
			restraintRdx.setSelected(node.getRestraint(0));
			restraintRdy.setSelected(node.getRestraint(1));
			restraintRdz.setSelected(node.getRestraint(2));
			restraintRrx.setSelected(node.getRestraint(3));
			restraintRry.setSelected(node.getRestraint(4));
			restraintRrz.setSelected(node.getRestraint(5));
			
		} else {
			AngleField = new DecimalField(0, 7, numberFormat);
			
			FxField = new DecimalField(0, 7, numberFormat);
			FyField = new DecimalField(0, 7, numberFormat);
			FzField = new DecimalField(0, 7, numberFormat);
			MxField = new DecimalField(0, 7, numberFormat);
			MyField = new DecimalField(0, 7, numberFormat);
			MzField = new DecimalField(0, 7, numberFormat);
			
			KxField = new DecimalField(0, 7, numberFormat);
			KyField = new DecimalField(0, 7, numberFormat);
			KzField = new DecimalField(0, 7, numberFormat);
			KrxField = new DecimalField(0, 7, numberFormat);
			KryField = new DecimalField(0, 7, numberFormat);
			KrzField = new DecimalField(0, 7, numberFormat);
			
			DxField = new DecimalField(0, 7, numberFormat);
			DyField = new DecimalField(0, 7, numberFormat);
			DzField = new DecimalField(0, 7, numberFormat);
			RxField = new DecimalField(0, 7, numberFormat);
			RyField = new DecimalField(0, 7, numberFormat);
			RzField = new DecimalField(0, 7, numberFormat);
		}
		
	}
	
//*****************************************************************************
	
	/** Private inner class to handle check box events. */
	private class CheckBoxHandlerRdx implements ItemListener {
		public void itemStateChanged( ItemEvent event ) {
			if ( restraintRdx.isSelected() ) {
				labelRdx.setText("Dx = 0");
				figuraRdx.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintDx64.gif")) );
				if (springPossible)
					KxField.setEnabled(false);
			} else {
				labelRdx.setText("Dx       ");
				figuraRdx.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDx64.gif")) );
				KxField.setEnabled(true);
			}
		}
	}
	
//*****************************************************************************
	
	/** Private inner class to handle check box events. */
	private class CheckBoxHandlerRdy implements ItemListener {
		public void itemStateChanged( ItemEvent event ) {
			if ( restraintRdy.isSelected() ) {
				labelRdy.setText("Dy = 0");
				figuraRdy.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintDy64.gif")) );
				if (springPossible)
					KyField.setEnabled(false);
			} else {
				labelRdy.setText("Dy       ");
				figuraRdy.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDy64.gif")) );
				KyField.setEnabled(true);
			}
		}
	}
	
//*****************************************************************************
	
	/** Private inner class to handle check box events. */
	private class CheckBoxHandlerRdz implements ItemListener {
		public void itemStateChanged( ItemEvent event ) {
			if ( restraintRdz.isSelected() ) {
				labelRdz.setText("Dz = 0");
				figuraRdz.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintDz64.gif")) );
				if (springPossible)
					KzField.setEnabled(false);
			} else {
				labelRdz.setText("Dz       ");
				figuraRdz.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceDz64.gif")) );
				KzField.setEnabled(true);
			}
		}
	}
	
//*****************************************************************************
	
	/** Private inner class to handle check box events. */
	private class CheckBoxHandlerRrx implements ItemListener {
		public void itemStateChanged( ItemEvent event ) {
			if ( restraintRrx.isSelected() ) {
				labelRrx.setText("Rx = 0");
				figuraRrx.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintRx64.gif")) );
				if (springPossible)
					KrxField.setEnabled(false);
			} else {
				labelRrx.setText("Rx       ");
				figuraRrx.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRx64.gif")) );
				KrxField.setEnabled(true);
			}
		}
	}
	
//*****************************************************************************
	
	/** Private inner class to handle check box events. */
	private class CheckBoxHandlerRry implements ItemListener {
		public void itemStateChanged( ItemEvent event ) {
			if ( restraintRry.isSelected() ) {
				labelRry.setText("Ry = 0");
				figuraRry.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintRy64.gif")) );
				if (springPossible)
					KryField.setEnabled(false);
			} else {
				labelRry.setText("Ry       ");
				figuraRry.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRy64.gif")) );
				KryField.setEnabled(true);
			}
		}
	}
	
//*****************************************************************************
	
	/** Private inner class to handle check box events. */
	private class CheckBoxHandlerRrz implements ItemListener {
		public void itemStateChanged( ItemEvent event ) {
			if ( restraintRrz.isSelected() ) {
				labelRrz.setText("Rz = 0");
				figuraRrz.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/RestraintRz64.gif")) );
				if (springPossible)
					KrzField.setEnabled(false);
			} else {
				labelRrz.setText("Rz       ");
				figuraRrz.setIcon( new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/DisplaceRz64.gif")) );
				KrzField.setEnabled(true);
			}
		}
	}
	
//*****************************************************************************
	
	/** Private inner class to handle JTextField events. */
	private class AngleFieldHandler implements KeyListener {
		
		public void keyReleased(KeyEvent event) {
			try {
				double value = AngleField.getValue();
				
				if (value != 0) {
					springPossible = false;
					if (KxField.isEnabled()) {
						KxField.setEnabled(false);
						KxField.setValue(0);
					}
					if (KyField.isEnabled()) {
						KyField.setEnabled(false);
						KyField.setValue(0);
					}
					if (KzField.isEnabled()) {
						KzField.setEnabled(false);
						KzField.setValue(0);
					}
					if (KrxField.isEnabled()) {
						KrxField.setEnabled(false);
						KrxField.setValue(0);
					}
					if (KryField.isEnabled()) {
						KryField.setEnabled(false);
						KryField.setValue(0);
					}
					if (KrzField.isEnabled()) {
						KrzField.setEnabled(false);
						KrzField.setValue(0);
					}
					
				} else {
					
					springPossible = true;
					if (restraintRdx.isSelected())
						KxField.setEnabled(true);
					if (restraintRdy.isSelected())
						KyField.setEnabled(true);
					if (restraintRdz.isSelected())
						KzField.setEnabled(true);
					if (restraintRrx.isSelected())
						KrxField.setEnabled(true);
					if (restraintRry.isSelected())
						KryField.setEnabled(true);
					if (restraintRrz.isSelected())
						KrzField.setEnabled(true);
					
				}
			} catch (Exception e) {}
		}
		public void keyTyped(KeyEvent event) {}
		public void keyPressed(KeyEvent event) {}
	}
	
//*****************************************************************************
}

